"""
我们将创建一个 Shape 接口和实现 Shape 接口的实体类。下一步是定义工厂类 ShapeFactory。
FactoryPatternDemo 类使用 ShapeFactory 来获取 Shape 对象。
它将向 ShapeFactory 传递信息（CIRCLE / RECTANGLE / SQUARE），以便获取它所需对象的类型。
"""
from abc import ABC, abstractmethod
from typing import Optional


# 抽象产品 A
class Shape(ABC):
    @abstractmethod
    def draw(self):
        pass


# 具体产品 A1
class Circle(Shape):
    def draw(self):
        print('draw circle...')


# 具体产品 A2
class Square(Shape):
    def draw(self):
        print('draw square...')


# 具体产品 A3
class Rectangle(Shape):
    def draw(self):
        print('draw rectangle...')


# 创建工厂
class ShapeFactory:
    def get_shape(self, shape_type) -> Optional[Shape]:
        if shape_type is None:
            return None

        if shape_type.upper() == 'circle'.upper():
            return Circle()
        elif shape_type.upper() == 'rectangle'.upper():
            return Rectangle()
        elif shape_type.upper() == 'square'.upper():
            return Square()

        return None


"""
# 抽象工厂 A
class ShapeFactory(ABC):
    @abstractmethod
    def get_shape(self):
        pass


# 具体工厂 A1
class CircleFactory(ShapeFactory):
    def get_shape(self):
        return Circle()


# 具体工厂 A2
class SquareFactory(ShapeFactory):
    def get_shape(self):
        return Square()


# 具体工厂 A3
class RectangleFactory(ShapeFactory):
    def get_shape(self):
        return Rectangle()


def client(shape: Shape):
    shape.draw()
"""

if __name__ == '__main__':
    factory = ShapeFactory()
    circle = factory.get_shape('rectangle')
    circle.draw()
"""
    circle_factory = CircleFactory()
    square_factory = SquareFactory()
    rectangle_factory = RectangleFactory()

    circle = circle_factory.get_shape()
    square = square_factory.get_shape()
    rectangle = rectangle_factory.get_shape()

    client(circle)
    client(square)
    client(rectangle)

"""
